<?php

/*
 * Niken Larasati
 * larasati.n@students.amikom.ac.id
 */

class jenis_pindah extends CI_Controller{
    public function __construct() {
        parent::__construct();
    }
    
    function form_jenis_pindah(){
        $this->template->load('halaman_v','admin/jenis_pindah/tambah_jenis_pindah_v');
    }
    
    function tambah(){
        if($this->input->post('tambah') != NULL);
        {
            $data['idjenis_pindah'] = $this->input->post('idjenis_pindah');
            $data['jenis_pindah'] = $this->input->post('jenis_pindah');
            
            $this->load->model('umum_m');
            $this->umum_m->tambah('jenis_pindah',$data);
            $this->tampil();
        }
    }
    
    function ubah($id = NULL) {
        if ($id != NULL) {
            $this->load->model('umum_m');
            $data['data_jenis_pindah'] = $this->umum_m->ambil_data('jenis_pindah', 'idjenis_pindah = ' . $id)->row();
            $this->template->load('halaman_v', 'admin/jenis_pindah/ubah_jenis_pindah_v', $data);
        } else {
            redirect('admin/jenis_pindah');
        }
    }
    
    function simpan_ubah() { //kalau data tidak diubah,maka....?
        if ($this->input->post() != null) {
            $jenis_pindah['idjenis_pindah'] = $this->input->post('idjenis_pindah');
            $jenis_pindah['jenis_pindah'] = $this->input->post('jenis_pindah');

            $this->load->model('umum_m');
            if ($this->umum_m->ubah('jenis_pindah', $jenis_pindah, 'idjenis_pindah', $jenis_pindah['idjenis_pindah'])) {
                redirect('admin/jenis_pindah/tampil');
            }
        }
    }
    
    function tampil(){
        $this->load->model('jenis_pindah_m');
        $data['jenis_pindah'] = $this->jenis_pindah_m->ambil_data();
        $this->template->load('halaman_v','admin/jenis_pindah/tampil_jenis_pindah_v',$data);
    }
    
    function hapus($id = NULL){
        if($id != NULL){
            $this->load->model('umum_m');
            $status = $this->umum_m->cek_relasi_tabel('pindah_pergi','idjenis_pindah',$id);
            if($status == 0){
                $this->umum_m->hapus_data_tabel('jenis_pindah',  array('idjenis_pindah'=>$id));
                $this->tampil();
            }
        }        
    }
}
?>

